package com.xu.demo.prototypePattern;

public class prototypePattern {

    public static void main(String[] args) throws CloneNotSupportedException {
        test2();
    }

    public static void test2() throws CloneNotSupportedException {
        ConcretePrototype c1 = new ConcretePrototype();
        Person p1 = new Person();
        c1.setPerson(p1);

        //复制c1
        ConcretePrototype c2 = c1.clone();
        //获取复制对象c2中的Person对象
        Person p2 = c2.getPerson();
        p2.setName("峰哥");

        //判断p1与p2是否是同一对象
        System.out.println("p1和p2是同一个对象？" + (p1 == p2));

        c1.show();
        c2.show();
    }

    //    public static void test1() throws CloneNotSupportedException {
    //        ConcretePrototype c1 = new ConcretePrototype();
    //        ConcretePrototype c2 = c1.clone();
    //
    //        System.out.println("对象c1和c2是同一个对象？" + (c1 == c2));
    //    }
}
